package com.isunland.managesystem.ui;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseTimeDialogFragment;
import java.util.Date;

/**
 * 用于填写本阶段完成时间
 *
 * @author wangyanan
 */
public class WorkProgressTimeDialogFragment extends BaseTimeDialogFragment {
  private static final String EXTRA_REQUIRE_TIME =
      "com.isunland.managesystem.ui.EXTRA_REQUIRE_TIME";

  @Override public boolean condition(Date mDate, Date mStartDate) {
    boolean isRequire = getArguments().getBoolean(EXTRA_REQUIRE_TIME);
    //如果是要求完成时间不进行条件判断.
    if (isRequire) {
      return false;
    }
    if (mDate.before(new Date())) {
      setResult(Activity.RESULT_OK);
    } else {
      Toast.makeText(getActivity(), R.string.earlyThanCurrentTime, Toast.LENGTH_SHORT).show();
    }

    return true;
  }

  /**
   * @param isRequireTime 是否选择的是要求完成时间
   */
  public static BaseTimeDialogFragment newInstance(Date startDate, int titleId,
      boolean isRequireTime) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_START_DATE, startDate);
    args.putInt(EXTRA_TITLE_ID, titleId);
    args.putBoolean(EXTRA_REQUIRE_TIME, isRequireTime);
    BaseTimeDialogFragment fragment = new WorkProgressTimeDialogFragment();
    fragment.setArguments(args);
    return fragment;
  }

  public static BaseTimeDialogFragment newInstance(Date startDate, int titleId) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_START_DATE, startDate);
    args.putInt(EXTRA_TITLE_ID, titleId);
    BaseTimeDialogFragment fragment = new WorkProgressTimeDialogFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
